﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Web.SessionState;

namespace Web.User.Storage
{
    /// <summary>
    /// storage 的摘要说明
    /// </summary>
    public class storage : IHttpHandler,IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            common.IsLogin();
            if (context.Request.QueryString["type"] != null)
            {
                string strType = context.Request.QueryString["type"].ToString();
                switch (strType)
                {

                    case "GetStorageVarietyUnitByID": GetStorageVarietyUnitByID(context); break;//获取存储产品的计量单位
                    case "GetWeighNO": GetWeighNO(context); break;
                    case "GetVarietyFromStorageRate": GetVarietyFromStorageRate(context); break;
                    case "GetUnitByVarietyID": GetUnitByVarietyID(context); break;

                    case "GetTypeFromVarietyRate": GetTypeFromVarietyRate(context); break;
                    case "GetUserTypeByVarietyID": GetUserTypeByVarietyID(context); break;
                    case "GetTimeByVUID": GetTimeByVUID(context); break;
                    case "GetSotorageByVUTID": GetSotorageByVUTID(context); break;
                    case "ShowOptionInfo": ShowOptionInfo(context); break;

                    case "Add_Dep_Storage": Add_Dep_Storage(context); break;
                    case "Update_Dep_Storage": Update_Dep_Storage(context); break;
                    case "Delete_Dep_Storage": Delete_Dep_Storage(context); break;
                        
                    case "GetByID_Dep_Storage": GetByID_Dep_Storage(context); break;

                    case "GetDepositorPrint": GetDepositorPrint(context); break;
                 
                    case "GetNewBusinessNO": GetNewBusinessNO(context); break;
                }
            }

        }

        /// <summary>
        /// 获取新的业务编号
        /// </summary>
        /// <param name="context"></param>
        void GetNewBusinessNO(HttpContext context)
        {

            string AccountNumber = context.Request.QueryString["AccountNumber"].ToString();

            string BusinessNO = "001";
            //查询当前社员的业务编号
            StringBuilder strSqlNO = new StringBuilder();
            strSqlNO.Append("  SELECT TOP 1 BusinessNO ");
            strSqlNO.Append("  FROM dbo.Dep_OperateLog  ");
            strSqlNO.Append("  WHERE Dep_AccountNumber='" + AccountNumber + "'");
            strSqlNO.Append("  ORDER BY dt_Trade DESC");
            object obj = SQLHelper.ExecuteScalar(strSqlNO.ToString());
            if (obj != null && obj.ToString() != "")
            {
                int BNO = Convert.ToInt32(obj) + 1;
                BusinessNO = Fun.ConvertIntToString(BNO, 3);
            }

            context.Response.Write(BusinessNO);
        }

        /// <summary>
        /// 获取储户的打印信息
        /// </summary>
        /// <param name="context"></param>
        void GetDepositorPrint(HttpContext context)
        {
            //获取需要打印的信息
            string AccountNumber = context.Request.QueryString["AccountNumber"].ToString();

            StringBuilder strSqlCommume = new StringBuilder();
            strSqlCommume.Append("SELECT A.AccountNumber,A.strName,A.strAddress,A.IDCard,B.strName AS WBID,'密码' AS OperateWay, PhoneNO, CONVERT(NVARCHAR(100),A.dt_Add,23) AS dt_Add");
            strSqlCommume.Append(" FROM dbo.Depositor A INNER JOIN dbo.WB B ON A.WBID=B.ID");
            strSqlCommume.Append(" WHERE A.AccountNumber='"+AccountNumber+"'");
           

            DataTable dtCommune = SQLHelper.ExecuteDataTable(strSqlCommume.ToString());
            if (dtCommune == null || dtCommune.Rows.Count == 0)
            {
                context.Response.Write("");
                return;
            }

            string strName = dtCommune.Rows[0]["strName"].ToString();
            string strAddress = dtCommune.Rows[0]["strAddress"].ToString();
            string IDCard = dtCommune.Rows[0]["IDCard"].ToString();
            string WBID = dtCommune.Rows[0]["WBID"].ToString();
            string PhoneNO = dtCommune.Rows[0]["PhoneNO"].ToString();
            string dt_Commune = dtCommune.Rows[0]["dt_Add"].ToString();
            string OperateWay = dtCommune.Rows[0]["OperateWay"].ToString();

            if (Convert.ToBoolean(common.GetWBAuthority()["ISPrintIDCard"]) == false)
            {
                IDCard = "******";
            }

            if (Convert.ToBoolean(common.GetWBAuthority()["ISPrintPhoneNo"]) == false)
            {
                PhoneNO = "******";
            }

            string strWBID = context.Session["WB_ID"].ToString();
            string strSql = " SELECT ID,Width,Height,DriftRateX,DriftRateY,FontSize,HomeR1C1X,HomeR1C1Y,HomeR1C2X,HomeR1C2Y,HomeR2C1X,HomeR2C1Y,HomeR2C2X,HomeR2C2Y,HomeR3C1X,HomeR3C1Y,HomeR3C2X,HomeR3C2Y,HomeR4C1X,HomeR4C1Y,HomeR4C2X,HomeR4C2Y,HomeR5C1X,HomeR5C1Y,HomeR5C2X,HomeR5C2Y,RecordR1Y,RecordR2Y,RecordR3Y,RecordR4Y,RecordR5Y,RecordR6Y,RecordR7Y,RecordR8Y,RecordR9Y,RecordR10Y,RecordR11Y,RecordR12Y,RecordR13Y,RecordR14Y,RecordR15Y,RecordR16Y,RecordR17Y,RecordR18Y,RecordR19Y,RecordR20Y,RecordC1X,RecordC2X,RecordC3X,RecordC4X,RecordC5X,RecordC6X,RecordC7X,RecordC8X,RecordC9X ";
            strSql += "   FROM [PrintSetting_Dep] ";
            strSql += "  where 1=1 and WBID="+strWBID;

            DataTable dt = SQLHelper.ExecuteDataTable(strSql);
            if (dt != null && dt.Rows.Count != 0)
            {

                string HomeR1C1X = dt.Rows[0]["HomeR1C1X"].ToString();
                string HomeR1C1Y = dt.Rows[0]["HomeR1C1Y"].ToString();
                string HomeR1C2X = dt.Rows[0]["HomeR1C2X"].ToString();
                string HomeR1C2Y = dt.Rows[0]["HomeR1C2Y"].ToString();

                string HomeR2C1X = dt.Rows[0]["HomeR2C1X"].ToString();
                string HomeR2C1Y = dt.Rows[0]["HomeR2C1Y"].ToString();
                string HomeR2C2X = dt.Rows[0]["HomeR2C2X"].ToString();
                string HomeR2C2Y = dt.Rows[0]["HomeR2C2Y"].ToString();

                string HomeR3C1X = dt.Rows[0]["HomeR3C1X"].ToString();
                string HomeR3C1Y = dt.Rows[0]["HomeR3C1Y"].ToString();
                string HomeR3C2X = dt.Rows[0]["HomeR3C2X"].ToString();
                string HomeR3C2Y = dt.Rows[0]["HomeR3C2Y"].ToString();

                string HomeR4C1X = dt.Rows[0]["HomeR4C1X"].ToString();
                string HomeR4C1Y = dt.Rows[0]["HomeR4C1Y"].ToString();
                string HomeR4C2X = dt.Rows[0]["HomeR4C2X"].ToString();
                string HomeR4C2Y = dt.Rows[0]["HomeR4C2Y"].ToString();

                string HomeR5C1X = dt.Rows[0]["HomeR5C1X"].ToString();
                string HomeR5C1Y = dt.Rows[0]["HomeR5C1Y"].ToString();
                string HomeR5C2X = dt.Rows[0]["HomeR5C2X"].ToString();
                string HomeR5C2Y = dt.Rows[0]["HomeR5C2Y"].ToString();

                StringBuilder strReturn = new StringBuilder();
                strReturn.Append("  <table style='height:" + HomeR1C1Y + "px'><tr><td></td> </tr></table>");
                strReturn.Append("  <table style='height:" + (Convert.ToInt32(HomeR2C1Y) - Convert.ToInt32(HomeR1C1Y)).ToString() + "px'><tr>");
                strReturn.Append("   <td style='width:" + HomeR1C1X + "px;'></td>");
                strReturn.Append("   <td style='font-size:20px; font-weight:bolder; width:" + (Convert.ToInt32(HomeR1C2X) - Convert.ToInt32(HomeR1C1X)).ToString() + "px;'>" + AccountNumber + "</td>");
                strReturn.Append("   <td style='font-size:20px; font-weight:bolder;'>" + strName + "</td>");
                strReturn.Append("   </tr></table>");

                strReturn.Append("  <table style='height:" + (Convert.ToInt32(HomeR3C1Y) - Convert.ToInt32(HomeR2C1Y)).ToString() + "px'><tr>");
                strReturn.Append("   <td style='width:" + HomeR2C1X + "px;'></td>");
                strReturn.Append("   <td style='font-size:14px; font-weight:bold;width:" + (Convert.ToInt32(HomeR2C2X) - Convert.ToInt32(HomeR2C1X)).ToString() + "px;'>" + strAddress + "</td>");
                strReturn.Append("   <td style='font-size:14px; font-weight:bold;'>"+IDCard+"</td>");
                strReturn.Append("   </tr></table>");

                strReturn.Append("  <table style='height:" + (Convert.ToInt32(HomeR4C1Y) - Convert.ToInt32(HomeR3C1Y)).ToString() + "px'><tr>");
                strReturn.Append("   <td style='width:" + HomeR3C1X + "px;'></td>");
                strReturn.Append("   <td style='font-size:14px; font-weight:bold;width:" + (Convert.ToInt32(HomeR3C2X) - Convert.ToInt32(HomeR3C1X)).ToString() + "px;'>" + WBID + "</td>");
                strReturn.Append("  <td style='font-size:14px; font-weight:bold;'>"+OperateWay+"</td>");
                strReturn.Append("   </tr></table>");

                strReturn.Append("  <table style='height:" + (Convert.ToInt32(HomeR5C1Y) - Convert.ToInt32(HomeR4C1Y)).ToString() + "px'><tr>");
                strReturn.Append("   <td style='width:" + HomeR4C1X + "px;'></td>");
                strReturn.Append("   <td style='font-size:14px; font-weight:bold;width:" + (Convert.ToInt32(HomeR4C2X) - Convert.ToInt32(HomeR4C1X)).ToString() + "px;'>" + PhoneNO + "</td>");
                strReturn.Append("   <td style='font-size:14px; font-weight:bold;' >" + dt_Commune + "</td>");

                strReturn.Append("   </tr></table>");

                //是否打印价格政策
                if (Convert.ToBoolean(common.GetWBAuthority()["Price_PrintOnCunZhe"]) == true)
                {
                    string strSqlPolicy = " SELECT TOP 1 strRemark  FROM dbo.BD_Company";

                    object objPolicy = SQLHelper.ExecuteScalar(strSqlPolicy);

                    strReturn.Append("  <div style='font-size:12px; font-weight:bold;padding-left:20px; height:" + (Convert.ToInt32(HomeR5C1Y) - Convert.ToInt32(HomeR4C1Y)).ToString() + "px'>");

                    strReturn.Append("<p>" + objPolicy.ToString() + "</p>");

                    strReturn.Append("  </div>");
                }


                context.Response.Write(strReturn.ToString());
            }
            else
            {
                context.Response.Write("Error");
            }
        }



        

        /// <summary>
        /// 获取存储产品的计量单位
        /// </summary>
        /// <param name="context"></param>
        void GetStorageVarietyUnitByID(HttpContext context)
        {
            string VarietyID = context.Request.QueryString["VarietyID"].ToString();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  SELECT TOP 1 B.strName");
            strSql.Append("  FROM dbo.StorageVariety A INNER JOIN dbo.BD_MeasuringUnit B ON A.MeasuringUnitID=B.ID");
            strSql.Append("  WHERE A.ID=" + VarietyID);

            object obj = SQLHelper.ExecuteScalar(strSql.ToString());

            if (obj != null)
            {
                context.Response.Write(obj.ToString());
            }
            else
            {
                context.Response.Write("Error");
            }
        }


        /// <summary>
        /// 获取磅单编号(许修改)
        /// </summary>
        /// <param name="context"></param>
        void GetWeighNO(HttpContext context)
        {
            string strYear = Fun.ConvertIntToString(DateTime.Now.Year, 4);
            string strMonth = Fun.ConvertIntToString(DateTime.Now.Month, 2);
            string strDay = Fun.ConvertIntToString(DateTime.Now.Day, 2);
            string strWeighNO = strYear + strMonth + strDay + "0000600001";
            context.Response.Write(strWeighNO);
        }

        /// <summary>
        /// 获取存储利率表中的存储产品信息
        /// </summary>
        /// <param name="context"></param>
        void GetVarietyFromStorageRate(HttpContext context)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  SELECT DISTINCT B.ID,B.strName");
            strSql.Append(" FROM dbo.StorageRate A INNER JOIN dbo.StorageVariety B ON A.VarietyID=B.ID");

            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            if (dt != null&&dt.Rows.Count!=0)
            {
                context.Response.Write(JsonHelper.ToJson(dt));
            }
            else
            {
                context.Response.Write("Error");
            }
        }

        /// <summary>
        /// 根据存储产品ID获取存储产品的单位
        /// </summary>
        /// <param name="context"></param>
        void GetUnitByVarietyID(HttpContext context)
        {
            string VarietyID = context.Request.QueryString["VarietyID"].ToString(); 
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  SELECT B.strName");
            strSql.Append(" FROM dbo.StorageVariety A INNER JOIN dbo.BD_MeasuringUnit B ON A.MeasuringUnitID=B.ID");
            strSql.Append("  WHERE A.ID= " + VarietyID);
            object obj = SQLHelper.ExecuteScalar(strSql.ToString());
            if (obj!=null)
            {
                context.Response.Write(obj.ToString());
            }
            else
            {
                context.Response.Write("Error");
            }
        }

        void GetTypeFromVarietyRate(HttpContext context)
        {
           
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT  DISTINCT B.ID,B.strName");
            strSql.Append(" FROM  dbo.StorageRate A INNER JOIN dbo.StorageType B ON A.TypeID=B.ID");
         
            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            if (dt != null && dt.Rows.Count != 0)
            {
                context.Response.Write(JsonHelper.ToJson(dt));
            }
            else
            {
                context.Response.Write("Error");
            }
        }

        /// <summary>
        /// 根据存储产品ID获取与之关联的储户类型(storageRate表)
        /// </summary>
        /// <param name="context"></param>
        void GetUserTypeByVarietyID(HttpContext context)
        {
            string VarietyID = context.Request.QueryString["VarietyID"].ToString(); 
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT  DISTINCT B.ID,B.strName");
            strSql.Append(" FROM  dbo.StorageRate A INNER JOIN dbo.StorageType B ON A.TypeID=B.ID");
            strSql.Append("  WHERE VarietyID= " + VarietyID);
            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            if (dt != null&&dt.Rows.Count!=0)
            {
                context.Response.Write(JsonHelper.ToJson(dt));
            }
            else
            {
                context.Response.Write("Error");
            }
        }

        /// <summary>
        /// 根据存储产品ID和储户类型获取与之关联的存期类型(storageRate表)
        /// </summary>
        /// <param name="context"></param>
        void GetTimeByVUID(HttpContext context)
        {
            string VarietyID = context.Request.QueryString["VarietyID"].ToString();
            string TypeID = context.Request.QueryString["TypeID"].ToString(); 
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT  DISTINCT B.ID,B.strName");
            strSql.Append(" FROM  dbo.StorageRate A INNER JOIN dbo.StorageTime B ON A.TimeID=B.ID");
            strSql.Append("  WHERE A.VarietyID= " + VarietyID + " and A.TypeID=" + TypeID);
            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            if (dt != null && dt.Rows.Count != 0)
            {
                context.Response.Write(JsonHelper.ToJson(dt));
            }
            else
            {
                context.Response.Write("Error");
            }
        }

        /// <summary>
        /// 根据存储产品ID\、户类型获、存期类型取与之关联的存储利率信息(storageRate表)
        /// </summary>
        /// <param name="context"></param>
        void GetSotorageByVUTID(HttpContext context)
        {
            string VarietyID = context.Request.QueryString["VarietyID"].ToString();
            string TypeID = context.Request.QueryString["TypeID"].ToString();
            string TimeID = context.Request.QueryString["TimeID"].ToString(); 
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" select ID,TypeID,VarietyID,VarietyLevelID,TimeID,StorageFee,BankRate,");
            strSql.Append(" CurrentRate,EarningRate,Price_ShiChang,Price_DaoQi,Price_HeTong,Price_XiaoShou ");
            strSql.Append(" FROM  dbo.StorageRate");
            strSql.Append("  WHERE VarietyID= " + VarietyID + " and TypeID=" + TypeID + " and TimeID=" + TimeID);
            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            if (dt != null && dt.Rows.Count != 0)
            {
                context.Response.Write(JsonHelper.ToJson(dt));
            }
            else
            {
                context.Response.Write("Error");
            }
        }


        /// <summary>
        /// 根据存储产品ID\、户类型获、存期类型取与之关联的存储利率信息(storageRate表)
        /// </summary>
        /// <param name="context"></param>
        void ShowOptionInfo(HttpContext context)
        {
            string VarietyID = context.Request.QueryString["VarietyID"].ToString();
            string TypeID = context.Request.QueryString["TypeID"].ToString();
            string TimeID = context.Request.QueryString["TimeID"].ToString();
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" select ID,TypeID,VarietyID,VarietyLevelID,TimeID,StorageFee,BankRate,");
            strSql.Append(" CurrentRate,EarningRate,Price_ShiChang,Price_DaoQi,Price_HeTong,Price_XiaoShou ");
            strSql.Append(" FROM  dbo.StorageRate");
            strSql.Append("  WHERE VarietyID= " + VarietyID + " and TypeID=" + TypeID + " and TimeID=" + TimeID);
            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            if (dt != null && dt.Rows.Count != 0)
            {
                string Price_ShiChang = dt.Rows[0]["Price_ShiChang"].ToString();
                string Price_DaoQi = dt.Rows[0]["Price_DaoQi"].ToString();
                string Price_HeTong = dt.Rows[0]["Price_HeTong"].ToString();
                string CurrentRate = dt.Rows[0]["CurrentRate"].ToString();
                string EarningRate = dt.Rows[0]["EarningRate"].ToString();
                //获取存储产品的计量单位
                string strUnit = "";
                StringBuilder strSqlUnit = new StringBuilder();
                strSqlUnit.Append("  SELECT TOP 1 B.strName");
                strSqlUnit.Append("  FROM dbo.StorageVariety A INNER JOIN dbo.BD_MeasuringUnit B ON A.MeasuringUnitID=B.ID");
                strSqlUnit.Append("  WHERE A.ID=" + VarietyID);

                object obj = SQLHelper.ExecuteScalar(strSqlUnit.ToString());
                if (obj != null)
                {
                    strUnit = obj.ToString();
                }
                //查询当前选项的结息方式
                StringBuilder strSqlTime = new StringBuilder();
                strSqlTime.Append(" SELECT strName,PricePolicy, InterestType,numStorageDate");
                strSqlTime.Append(" FROM  dbo.StorageTime");
                strSqlTime.Append(" WHERE ID=" + TimeID);
                DataTable dtTime = SQLHelper.ExecuteDataTable(strSqlTime.ToString());
                string strReturn = "";
                if (dtTime != null && dtTime.Rows.Count != 0)
                {
                    string strName = dtTime.Rows[0]["strName"].ToString();
                    string PricePolicy = dtTime.Rows[0]["PricePolicy"].ToString();
                    string InterestType = dtTime.Rows[0]["InterestType"].ToString();
                 
                    string numStorageDate = dtTime.Rows[0]["numStorageDate"].ToString();
                    strReturn += "当前选项: 存期：<b>" + strName + "</b>  存入价：<b>" + Price_ShiChang + "</b>元/" + strUnit;

                    switch (InterestType)
                    {
                        case "1": strReturn += ",活期利率：<b>" + CurrentRate + "</b>元/" + strUnit + "/月";
                            break;
                        case "2": strReturn += ",约定存储期限：<b>" + numStorageDate + "</b>天,到期受益比例：<b>" + EarningRate + "</b>";
                            break;
                        case "3": strReturn += ",约定存储期限：<b>" + numStorageDate + "</b>天,到期价：<b>" + Price_DaoQi + "</b>元/" + strUnit;
                            break;

                    }
                    strReturn += "  请注意存储产品与存期，并核对账号与数量";
                }

                context.Response.Write(strReturn.ToString());
            }
            else
            {
                context.Response.Write("Error");
            }
        }




        /// <summary>
        /// 添加储户存储信息
        /// </summary>
        /// <param name="context"></param>
        void Add_Dep_Storage(HttpContext context)
        {
            string BusinessNO = context.Request.Form["BusinessNO"].ToString();//交易号

            string AccountNumber = context.Request.QueryString["AccountNumber"].ToString();
            string StorageRateID = context.Request.Form["StorageRateID"].ToString();
            string VarietyID = context.Request.Form["VarietyID"].ToString();
            string TypeID = context.Request.Form["TypeID"].ToString();

            string TimeID = context.Request.Form["TimeID"].ToString();
            string StorageFee = context.Request.Form["StorageFee"].ToString();
            string WeighNo = context.Request.Form["WeighNO"].ToString();
            string StorageNumber = context.Request.Form["StorageNumber"].ToString();

            string CurrentRate = "";
            string Price_ShiChang = "";
            string Price_DaoQi = "";
            string Price_HeTong = "";

            //由价格与利率表获取当前的价格信息
            StringBuilder strSqlPrice = new StringBuilder();
            strSqlPrice.Append(" select ID,TypeID,VarietyID,VarietyLevelID,TimeID,StorageFee,BankRate,");
            strSqlPrice.Append(" CurrentRate,EarningRate,Price_ShiChang,Price_DaoQi,Price_HeTong,Price_XiaoShou ");
            strSqlPrice.Append(" FROM  dbo.StorageRate");
            strSqlPrice.Append("  WHERE VarietyID= " + VarietyID + " and TypeID=" + TypeID + " and TimeID=" + TimeID);
            DataTable dtPrice = SQLHelper.ExecuteDataTable(strSqlPrice.ToString());
            if (dtPrice != null && dtPrice.Rows.Count != 0)
            {
                CurrentRate = dtPrice.Rows[0]["CurrentRate"].ToString();
                Price_ShiChang = dtPrice.Rows[0]["Price_ShiChang"].ToString();
                Price_DaoQi = dtPrice.Rows[0]["Price_DaoQi"].ToString();
                Price_HeTong = dtPrice.Rows[0]["Price_HeTong"].ToString();
            }
            else {
                context.Response.Write("Price");
                return;
            }

            string UserID = context.Session["ID"].ToString();
            string WBID = context.Session["WB_ID"].ToString();


            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into [Dep_StorageInfo] (");
            strSql.Append("BusinessNO,AccountNumber,StorageRateID,VarietyID,TypeID,TimeID,InterestDate,StorageDate,WeighNo,StorageNumber,StorageNumberRaw,StorageFee,CurrentRate,Price_ShiChang,Price_DaoQi,Price_HeTong,UserID,WBID)");
            strSql.Append(" values (");
            strSql.Append("@BusinessNO,@AccountNumber,@StorageRateID,@VarietyID,@TypeID,@TimeID,@InterestDate,@StorageDate,@WeighNo,@StorageNumber,@StorageNumberRaw,@StorageFee,@CurrentRate,@Price_ShiChang,@Price_DaoQi,@Price_HeTong,@UserID,@WBID)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@BusinessNO", SqlDbType.NVarChar,50),
					new SqlParameter("@AccountNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@StorageRateID", SqlDbType.Int,4),
					new SqlParameter("@VarietyID", SqlDbType.Int,4),
					new SqlParameter("@TypeID", SqlDbType.Int,4),
					new SqlParameter("@TimeID", SqlDbType.Int,4),
					new SqlParameter("@InterestDate", SqlDbType.DateTime),
					new SqlParameter("@StorageDate", SqlDbType.DateTime),
					new SqlParameter("@WeighNo", SqlDbType.NVarChar,50),
					new SqlParameter("@StorageNumber", SqlDbType.Decimal,9),
					new SqlParameter("@StorageNumberRaw", SqlDbType.Decimal,9),
					new SqlParameter("@StorageFee", SqlDbType.Decimal,9),
					new SqlParameter("@CurrentRate", SqlDbType.Decimal,9),
					new SqlParameter("@Price_ShiChang", SqlDbType.Decimal,9),
					new SqlParameter("@Price_DaoQi", SqlDbType.Decimal,9),
					new SqlParameter("@Price_HeTong", SqlDbType.Decimal,9),
					new SqlParameter("@UserID", SqlDbType.Int,4),
                    new SqlParameter("@WBID", SqlDbType.Int,4)};
            parameters[0].Value = BusinessNO;
            parameters[1].Value = AccountNumber;
            parameters[2].Value = StorageRateID;
            parameters[3].Value = VarietyID;
            parameters[4].Value = TypeID;
            parameters[5].Value = TimeID;
            parameters[6].Value = DateTime.Now;
            parameters[7].Value = DateTime.Now;
            parameters[8].Value = WeighNo;
            parameters[9].Value = StorageNumber;
            parameters[10].Value = StorageNumber;
            parameters[11].Value = StorageFee;
            parameters[12].Value = CurrentRate;
            parameters[13].Value = Price_ShiChang;
            parameters[14].Value = Price_DaoQi;
            parameters[15].Value = Price_HeTong;
            parameters[16].Value = UserID;
            parameters[17].Value = WBID;

          

            //添加存粮记录
            StringBuilder strSqlLog = new StringBuilder();
            strSqlLog.Append("insert into [Dep_StorageLog] (");
            strSqlLog.Append("AccountNumber,StorageRateID,VarietyID,TypeID,TimeID,StorageDate,WeighNo,StorageNumber,StorageFee,CurrentRate,Price_ShiChang,Price_DaoQi,Price_HeTong,StorageNumberRaw,UserID,WBID)");
            strSqlLog.Append(" values (");
            strSqlLog.Append("@AccountNumber,@StorageRateID,@VarietyID,@TypeID,@TimeID,@StorageDate,@WeighNo,@StorageNumber,@StorageFee,@CurrentRate,@Price_ShiChang,@Price_DaoQi,@Price_HeTong,@StorageNumberRaw,@UserID,@WBID)");
            strSqlLog.Append(";select @@IDENTITY");
            SqlParameter[] parametersLog = {
					new SqlParameter("@AccountNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@StorageRateID", SqlDbType.Int,4),
					new SqlParameter("@VarietyID", SqlDbType.Int,4),
					new SqlParameter("@TypeID", SqlDbType.Int,4),
					new SqlParameter("@TimeID", SqlDbType.Int,4),
					new SqlParameter("@StorageDate", SqlDbType.DateTime),
					new SqlParameter("@WeighNo", SqlDbType.NVarChar,50),
					new SqlParameter("@StorageNumber", SqlDbType.Decimal,9),
					new SqlParameter("@StorageFee", SqlDbType.Decimal,9),
					new SqlParameter("@CurrentRate", SqlDbType.Decimal,9),
					new SqlParameter("@Price_ShiChang", SqlDbType.Decimal,9),
					new SqlParameter("@Price_DaoQi", SqlDbType.Decimal,9),
					new SqlParameter("@Price_HeTong", SqlDbType.Decimal,9),
                    new SqlParameter("@StorageNumberRaw", SqlDbType.Decimal,9),
                    new SqlParameter("@UserID", SqlDbType.Int,4),
                    new SqlParameter("@WBID", SqlDbType.Int,4)};
            parametersLog[0].Value = AccountNumber;
            parametersLog[1].Value = StorageRateID;
            parametersLog[2].Value = VarietyID;
            parametersLog[3].Value = TypeID;
            parametersLog[4].Value = TimeID;
            parametersLog[5].Value = DateTime.Now;
            parametersLog[6].Value = WeighNo;
            parametersLog[7].Value = StorageNumber;
            parametersLog[8].Value = StorageFee;
            parametersLog[9].Value = CurrentRate;
            parametersLog[10].Value = Price_ShiChang;
            parametersLog[11].Value = Price_DaoQi;
            parametersLog[12].Value = Price_HeTong;
            parametersLog[13].Value = StorageNumber;
            parametersLog[14].Value = UserID;
            parametersLog[15].Value = WBID;
            //添加交易记录
           
            string Price = Price_ShiChang;//价格
            string Count_Trade = StorageNumber;//存储数量
            string Money_Trade = "0";//存入的时候没有交易量
            string Count_Balance = StorageNumber;//当前产品结存（只要求当前的结存）
            //查找当前用户的当前产品的总的结存
            object objBalance = SQLHelper.ExecuteScalar("  SELECT SUM( StorageNumber)  AS StorageNumber  FROM dbo.Dep_StorageInfo WHERE AccountNumber='" + AccountNumber + "' AND VarietyID=" + VarietyID);
            if (objBalance != null && objBalance.ToString() != "")
            {
                Count_Balance = Math.Round(Convert.ToDecimal(objBalance) + Convert.ToDecimal(StorageNumber), 2).ToString();
            }

            string VarietyName = SQLHelper.ExecuteScalar("  SELECT strName FROM dbo.StorageVariety WHERE ID="+VarietyID).ToString();

            string TimeName = SQLHelper.ExecuteScalar(" SELECT TOP 1 strName FROM dbo.StorageTime WHERE ID="+TimeID).ToString();
            string UnitID = "公斤";
            object objUnitID = SQLHelper.ExecuteScalar(" SELECT strName FROM dbo.BD_MeasuringUnit WHERE ID=( SELECT MeasuringUnitID FROM dbo.StorageVariety WHERE ID="+VarietyID+")");//获取计价单位
            if (objUnitID != null && objUnitID.ToString() != "")
            {
                UnitID = objUnitID.ToString();
            }

            StringBuilder strSqlOperateLog = new StringBuilder();
            strSqlOperateLog.Append("insert into [Dep_OperateLog] (");
            strSqlOperateLog.Append("WBID,UserID,Dep_AccountNumber,BusinessNO,BusinessName,VarietyID,UnitID,Price,Count_Trade,Money_Trade,Count_Balance,dt_Trade)");
            strSqlOperateLog.Append(" values (");
            strSqlOperateLog.Append("@WBID,@UserID,@Dep_AccountNumber,@BusinessNO,@BusinessName,@VarietyID,@UnitID,@Price,@Count_Trade,@Money_Trade,@Count_Balance,@dt_Trade)");
            strSqlOperateLog.Append(";select @@IDENTITY");
            SqlParameter[] parametersOperateLog = {
					new SqlParameter("@WBID", SqlDbType.Int,4),
					new SqlParameter("@UserID", SqlDbType.Int,4),
					new SqlParameter("@Dep_AccountNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@BusinessNO", SqlDbType.NVarChar,50),
					new SqlParameter("@BusinessName", SqlDbType.NVarChar,50),
					new SqlParameter("@VarietyID", SqlDbType.NVarChar,50),
					new SqlParameter("@UnitID", SqlDbType.NVarChar,50),
					new SqlParameter("@Price", SqlDbType.Decimal,9),
					new SqlParameter("@Count_Trade", SqlDbType.Decimal,9),
					new SqlParameter("@Money_Trade", SqlDbType.Decimal,9),
					new SqlParameter("@Count_Balance", SqlDbType.Decimal,9),
					new SqlParameter("@dt_Trade", SqlDbType.DateTime)};
            parametersOperateLog[0].Value = WBID;
            parametersOperateLog[1].Value = UserID;
            parametersOperateLog[2].Value = AccountNumber;
            parametersOperateLog[3].Value = BusinessNO;
            parametersOperateLog[4].Value = "1";//1:存入 2：兑换  3:存转销 4: 提取
            parametersOperateLog[5].Value =TimeName+ VarietyName;
            parametersOperateLog[6].Value = UnitID;
            parametersOperateLog[7].Value = Price;
            parametersOperateLog[8].Value = Count_Trade;
            parametersOperateLog[9].Value = Money_Trade;
            parametersOperateLog[10].Value = Count_Balance;
            parametersOperateLog[11].Value = DateTime.Now;
          
            //添加事务处理
            using (SqlTransaction tran = SQLHelper.BeginTransaction(SQLHelper.connectionString))
            {
                try
                {

                    SQLHelper.ExecuteNonQuery(tran, CommandType.Text, strSql.ToString(), parameters);
                    SQLHelper.ExecuteNonQuery(tran, CommandType.Text, strSqlLog.ToString(), parametersLog);
                    SQLHelper.ExecuteNonQuery(tran, CommandType.Text, strSqlOperateLog.ToString(), parametersOperateLog);

                    //添加网点的产品库存记录
                    string VarietyStorageExit = " SELECT COUNT(ID)   FROM dbo.SA_VarietyStorage WHERE WBID="+WBID+" AND VarietyID="+VarietyID;
                    if (Convert.ToInt32(SQLHelper.ExecuteScalar(VarietyStorageExit)) <= 0)
                    {
                        StringBuilder VarietyStorageInsert = new StringBuilder();
                        VarietyStorageInsert.Append("insert into [SA_VarietyStorage] (");
                        VarietyStorageInsert.Append("VarietyID,WBID,numStorage,WareHouseID,ISHQ,ISSimulate)");
                        VarietyStorageInsert.Append(" values (");
                        VarietyStorageInsert.Append("@VarietyID,@WBID,@numStorage,@WareHouseID,@ISHQ,@ISSimulate)");
                        VarietyStorageInsert.Append(";select @@IDENTITY");
                        SqlParameter[] parametersVarietyStorageInsert = {
					new SqlParameter("@VarietyID", SqlDbType.Int,4),
					new SqlParameter("@WBID", SqlDbType.Int,4),
					new SqlParameter("@numStorage", SqlDbType.Decimal,9),
					new SqlParameter("@WareHouseID", SqlDbType.Int,4),
					new SqlParameter("@ISHQ", SqlDbType.Bit,1),
					new SqlParameter("@ISSimulate", SqlDbType.Bit,1)};
                        parametersVarietyStorageInsert[0].Value = VarietyID;
                        parametersVarietyStorageInsert[1].Value = WBID;
                        parametersVarietyStorageInsert[2].Value = StorageNumber;
                        parametersVarietyStorageInsert[3].Value = 1;//暂时不适用
                        parametersVarietyStorageInsert[4].Value = 0;
                        parametersVarietyStorageInsert[5].Value = 0;

                        SQLHelper.ExecuteNonQuery(tran, CommandType.Text, VarietyStorageInsert.ToString(), parametersVarietyStorageInsert);//首次添加网点产品的库存记录
                    }
                    else {
                        string VarietyStorageUpdate = " UPDATE dbo.SA_VarietyStorage SET numStorage=numStorage+" + StorageNumber + " WHERE WBID=" + WBID + " AND VarietyID=" + VarietyID;
                        SQLHelper.ExecuteNonQuery(tran, CommandType.Text, VarietyStorageUpdate.ToString());

                    }


                    tran.Commit();

                    context.Response.Write("OK");
                }
                catch
                {
                    tran.Rollback();
                    context.Response.Write("Error");
                }
            }
        }
       
        void Update_Dep_Storage(HttpContext context)
        {
            string BusinessNO = context.Request.Form["BusinessNO"].ToString();//交易号

            string ID = context.Request.QueryString["ID"].ToString();
            string editType = context.Request.Form["editType"].ToString();
            string WeighNo = context.Request.Form["WeighNO"].ToString();
            string StorageNumber = context.Request.Form["StorageNumber"].ToString();
            double numStorage = -Convert.ToDouble(StorageNumber);
            string strSqlEdit = "UPDATE dbo.Dep_StorageInfo SET WeighNo='" + WeighNo + "',StorageNumber=StorageNumber-" + StorageNumber + ",StorageNumberRaw= StorageNumberRaw-" + StorageNumber + " WHERE ID=" + ID;//修改存粮信息表
            //string strSqlEditLog = "UPDATE dbo.Dep_StorageLog SET WeighNo='" + WeighNo + "',StorageNumber=StorageNumber-" + StorageNumber + ",StorageNumberRaw= StorageNumberRaw-" + StorageNumber + " WHERE StorageInfoID=" + ID;//修改存粮记录表
            if (editType == "增加")
            {
                numStorage = Convert.ToDouble(StorageNumber);
                strSqlEdit = "UPDATE dbo.Dep_StorageInfo SET WeighNo='" + WeighNo + "',StorageNumber=StorageNumber+" + StorageNumber + ",StorageNumberRaw= StorageNumberRaw+" + StorageNumber + " WHERE ID=" + ID;

                //strSqlEditLog = "UPDATE dbo.Dep_StorageLog SET WeighNo='" + WeighNo + "',StorageNumber=StorageNumber+" + StorageNumber + ",StorageNumberRaw= StorageNumberRaw+" + StorageNumber + " WHERE StorageInfoID=" + ID;//修改存粮记录表
            }

            StringBuilder strSqlStorage = new StringBuilder();
            strSqlStorage.Append("select ID,BusinessNO,AccountNumber,StorageRateID,VarietyID,TypeID,TimeID,InterestDate,StorageDate,WeighNo,StorageNumber,StorageNumberRaw,StorageFee,CurrentRate,Price_ShiChang,Price_DaoQi,Price_HeTong,UserID ");
            strSqlStorage.Append(" FROM [Dep_StorageInfo] ");
            strSqlStorage.Append(" where ID=@ID ");
            SqlParameter[] parametersStorage = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
            parametersStorage[0].Value = ID;
            DataTable dtStorage = SQLHelper.ExecuteDataTable(strSqlStorage.ToString(), parametersStorage);
            double StorageNumber_Start = Convert.ToDouble(dtStorage.Rows[0]["StorageNumber"]);
            double num_balance = StorageNumber_Start + numStorage;
            string VarietyID = dtStorage.Rows[0]["VarietyID"].ToString();
            string AccountNumber = dtStorage.Rows[0]["AccountNumber"].ToString();

            //添加交易记录
           // string WBID = context.Session["WB_ID"].ToString();
            string strSqlWBID="SELECT WBID FROM dbo.Depositor WHERE AccountNumber=(SELECT AccountNumber FROM dbo.Dep_StorageInfo WHERE ID= "+ID+")";
            string WBID = SQLHelper.ExecuteScalar(strSqlWBID.ToString()).ToString();
            string UserID = context.Session["ID"].ToString();
            string Price = dtStorage.Rows[0]["Price_ShiChang"].ToString();//价格
            string Count_Trade = StorageNumber_Start.ToString();//存储数量
            string Money_Trade = numStorage.ToString();//存入的时候没有交易量
            string Count_Balance = num_balance.ToString();//当前产品结存
            //查找当前用户的当前产品的总的结存
            object objBalance = SQLHelper.ExecuteScalar("  SELECT SUM( StorageNumber)  AS StorageNumber  FROM dbo.Dep_StorageInfo WHERE AccountNumber='"+AccountNumber+"' AND VarietyID="+VarietyID);
            if (objBalance != null && objBalance.ToString() != "")
            {
                Count_Balance = Math.Round(Convert.ToDecimal(objBalance) + Convert.ToDecimal(numStorage), 2).ToString();
            }

            string VarietyName = SQLHelper.ExecuteScalar("  SELECT strName FROM dbo.StorageVariety WHERE ID="+VarietyID).ToString();
            string UnitID = "公斤";
            object objUnitID = SQLHelper.ExecuteScalar(" SELECT strName FROM dbo.BD_MeasuringUnit WHERE ID=( SELECT MeasuringUnitID FROM dbo.StorageVariety WHERE ID="+VarietyID+")");//获取计价单位
            if (objUnitID != null && objUnitID.ToString() != "")
            {
                UnitID = objUnitID.ToString();
            }

            StringBuilder strSqlOperateLog = new StringBuilder();
            strSqlOperateLog.Append("insert into [Dep_OperateLog] (");
            strSqlOperateLog.Append("WBID,UserID,Dep_AccountNumber,BusinessNO,BusinessName,VarietyID,UnitID,Price,Count_Trade,Money_Trade,Count_Balance,dt_Trade)");
            strSqlOperateLog.Append(" values (");
            strSqlOperateLog.Append("@WBID,@UserID,@Dep_AccountNumber,@BusinessNO,@BusinessName,@VarietyID,@UnitID,@Price,@Count_Trade,@Money_Trade,@Count_Balance,@dt_Trade)");
            strSqlOperateLog.Append(";select @@IDENTITY");
            SqlParameter[] parametersOperateLog = {
					new SqlParameter("@WBID", SqlDbType.Int,4),
					new SqlParameter("@UserID", SqlDbType.Int,4),
					new SqlParameter("@Dep_AccountNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@BusinessNO", SqlDbType.NVarChar,50),
					new SqlParameter("@BusinessName", SqlDbType.NVarChar,50),
					new SqlParameter("@VarietyID", SqlDbType.NVarChar,50),
					new SqlParameter("@UnitID", SqlDbType.NVarChar,50),
					new SqlParameter("@Price", SqlDbType.Decimal,9),
					new SqlParameter("@Count_Trade", SqlDbType.Decimal,9),
					new SqlParameter("@Money_Trade", SqlDbType.Decimal,9),
					new SqlParameter("@Count_Balance", SqlDbType.Decimal,9),
					new SqlParameter("@dt_Trade", SqlDbType.DateTime)};
            parametersOperateLog[0].Value = WBID;
            parametersOperateLog[1].Value = UserID;
            parametersOperateLog[2].Value = AccountNumber;
            parametersOperateLog[3].Value = BusinessNO;
            parametersOperateLog[4].Value = "5";//1:存入 2：兑换  3:存转销 4: 提取:5修改错误存量
            parametersOperateLog[5].Value = VarietyName;
            parametersOperateLog[6].Value = UnitID;
            parametersOperateLog[7].Value = Price;
            parametersOperateLog[8].Value = Count_Trade;
            parametersOperateLog[9].Value = Money_Trade;
            parametersOperateLog[10].Value = Count_Balance;
            parametersOperateLog[11].Value = DateTime.Now;
          
            //添加事务处理
            using (SqlTransaction tran = SQLHelper.BeginTransaction(SQLHelper.connectionString))
            {
                try
                {

                    SQLHelper.ExecuteNonQuery(tran, CommandType.Text, strSqlEdit.ToString());//更新储户存储信息

                    //SQLHelper.ExecuteNonQuery(tran, CommandType.Text, strSqlEditLog.ToString());//更新储户存储信息记录
                    
                    SQLHelper.ExecuteNonQuery(tran, CommandType.Text, strSqlOperateLog.ToString(), parametersOperateLog);

                    //修改网点的产品库存记录

                    if (editType == "增加")
                    {
                        string VarietyStorageUpdate = " UPDATE dbo.SA_VarietyStorage SET numStorage=numStorage+" + StorageNumber + " WHERE WBID=" + WBID + " AND VarietyID=" + VarietyID;
                        SQLHelper.ExecuteNonQuery(tran, CommandType.Text, VarietyStorageUpdate.ToString());
                    }
                    else {
                        string VarietyStorageUpdate = " UPDATE dbo.SA_VarietyStorage SET numStorage=numStorage-" + StorageNumber + " WHERE WBID=" + WBID + " AND VarietyID=" + VarietyID;
                        SQLHelper.ExecuteNonQuery(tran, CommandType.Text, VarietyStorageUpdate.ToString());
                    }

                    tran.Commit();

                    context.Response.Write("OK");
                }
                catch
                {
                    tran.Rollback();
                    context.Response.Write("Error");
                }
            }
           
        }

        /// <summary>
        /// 删除存粮记录
        /// </summary>
        /// <param name="context"></param>
        void Delete_Dep_Storage(HttpContext context)
        {
            string BusinessNO = context.Request.QueryString["BusinessNO"].ToString();//交易号
            string ID = context.Request.QueryString["ID"].ToString();
            

            //查询被退还的存储信息
            StringBuilder strSqlStorage = new StringBuilder();
            strSqlStorage.Append("select ID,BusinessNO,AccountNumber,StorageRateID,VarietyID,TypeID,TimeID,InterestDate,StorageDate,WeighNo,StorageNumber,StorageNumberRaw,StorageFee,CurrentRate,Price_ShiChang,Price_DaoQi,Price_HeTong,UserID ");
            strSqlStorage.Append(" FROM [Dep_StorageInfo] ");
            strSqlStorage.Append(" where ID= "+ID);
            DataTable dtStorage = SQLHelper.ExecuteDataTable(strSqlStorage.ToString());

            if (dtStorage == null || dtStorage.Rows.Count == 0)//此条存粮信息已经被删除
            {
                context.Response.Write("0");
                return;
            }
            //添加退还日志记录
          
            double StorageNumber= Convert.ToDouble(dtStorage.Rows[0]["StorageNumber"]);
            string VarietyID = dtStorage.Rows[0]["VarietyID"].ToString();
            string AccountNumber = dtStorage.Rows[0]["AccountNumber"].ToString();

            //添加交易记录
            string WBID = context.Session["WB_ID"].ToString();
            string UserID = context.Session["ID"].ToString();
            string Price = dtStorage.Rows[0]["Price_ShiChang"].ToString();//价格

            string VarietyName = SQLHelper.ExecuteScalar("  SELECT strName FROM dbo.StorageVariety WHERE ID=" + VarietyID).ToString();
            string UnitID = "公斤";
            object objUnitID = SQLHelper.ExecuteScalar(" SELECT strName FROM dbo.BD_MeasuringUnit WHERE ID=( SELECT MeasuringUnitID FROM dbo.StorageVariety WHERE ID=" + VarietyID + ")");//获取计价单位
            if (objUnitID != null && objUnitID.ToString() != "")
            {
                UnitID = objUnitID.ToString();
            }

            StringBuilder strSqlOperateLog = new StringBuilder();
            strSqlOperateLog.Append("insert into [Dep_OperateLog] (");
            strSqlOperateLog.Append("WBID,UserID,Dep_AccountNumber,BusinessNO,BusinessName,VarietyID,UnitID,Price,Count_Trade,Money_Trade,Count_Balance,dt_Trade)");
            strSqlOperateLog.Append(" values (");
            strSqlOperateLog.Append("@WBID,@UserID,@Dep_AccountNumber,@BusinessNO,@BusinessName,@VarietyID,@UnitID,@Price,@Count_Trade,@Money_Trade,@Count_Balance,@dt_Trade)");
            strSqlOperateLog.Append(";select @@IDENTITY");
            SqlParameter[] parametersOperateLog = {
					new SqlParameter("@WBID", SqlDbType.Int,4),
					new SqlParameter("@UserID", SqlDbType.Int,4),
					new SqlParameter("@Dep_AccountNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@BusinessNO", SqlDbType.NVarChar,50),
					new SqlParameter("@BusinessName", SqlDbType.NVarChar,50),
					new SqlParameter("@VarietyID", SqlDbType.NVarChar,50),
					new SqlParameter("@UnitID", SqlDbType.NVarChar,50),
					new SqlParameter("@Price", SqlDbType.Decimal,9),
					new SqlParameter("@Count_Trade", SqlDbType.Decimal,9),
					new SqlParameter("@Money_Trade", SqlDbType.Decimal,9),
					new SqlParameter("@Count_Balance", SqlDbType.Decimal,9),
					new SqlParameter("@dt_Trade", SqlDbType.DateTime)};
            parametersOperateLog[0].Value = WBID;
            parametersOperateLog[1].Value = UserID;
            parametersOperateLog[2].Value = AccountNumber;
            parametersOperateLog[3].Value = BusinessNO;
            parametersOperateLog[4].Value = "8";//1:存入 2：兑换  3:存转销 4: 提取:5修改错误存量
            parametersOperateLog[5].Value = VarietyName;
            parametersOperateLog[6].Value = UnitID;
            parametersOperateLog[7].Value = Price;
            parametersOperateLog[8].Value = -StorageNumber;
            parametersOperateLog[9].Value = StorageNumber;
            parametersOperateLog[10].Value = 0;
            parametersOperateLog[11].Value = DateTime.Now;


            string strSqlDelete = " DELETE FROM dbo.Dep_StorageInfo WHERE ID="+ID;

            //修改该产品在网点中的库存
            string strSqlVarietyStorage = "UPDATE dbo.SA_VarietyStorage SET numStorage=numStorage-"+StorageNumber+" WHERE WBID="+WBID+" AND VarietyID="+VarietyID;
            //添加事务处理
            using (SqlTransaction tran = SQLHelper.BeginTransaction(SQLHelper.connectionString))
            {
                try
                {

                   

                    SQLHelper.ExecuteNonQuery(tran, CommandType.Text, strSqlOperateLog.ToString(), parametersOperateLog);//添加退还日志记录

                    SQLHelper.ExecuteNonQuery(tran, CommandType.Text, strSqlDelete.ToString());//删除存粮记录
                    SQLHelper.ExecuteNonQuery(tran, CommandType.Text, strSqlVarietyStorage.ToString());//修改网点库存

                   
                    tran.Commit();

                    context.Response.Write("OK");
                }
                catch
                {
                    tran.Rollback();
                    context.Response.Write("Error");
                }
            }

        }

        /// <summary>
        /// 添加储户存储信息
        /// </summary>
        /// <param name="context"></param>
        void GetByID_Dep_Storage(HttpContext context)
        {
            string ID = context.Request.QueryString["ID"].ToString();

            //获取存粮信息
            StringBuilder strSqlStorage = new StringBuilder();
            strSqlStorage.Append("SELECT A.ID,A.StorageNumber,A.StorageDate,A.WeighNo, A.AccountNumber,B.strName AS VarietyID,A.Price_ShiChang,A.Price_DaoQi,C.strName AS TimeID,A.StorageFee");
            strSqlStorage.Append("  FROM dbo.Dep_StorageInfo A INNER JOIN dbo.StorageVariety B ON A.VarietyID=B.ID");
            strSqlStorage.Append("  INNER JOIN dbo.StorageTime C ON A.TimeID=C.ID");
            strSqlStorage.Append("  WHERE A.ID=" + ID);
            DataTable dtStorage = SQLHelper.ExecuteDataTable(strSqlStorage.ToString());

            if (dtStorage!=null&&dtStorage.Rows.Count!=0)
            {
                context.Response.Write(JsonHelper.ToJson(dtStorage));
            }
            else
            {
                context.Response.Write("Error");
            }
        }


        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}